package com.bw.produce.controller;

import com.bw.common.core.domain.R;
import com.bw.common.core.web.controller.BaseController;
import com.bw.common.core.web.domain.AjaxResult;
import com.bw.common.core.web.page.TableDataInfo;
import com.bw.produce.domain.Classify;
import com.bw.produce.domain.dto.ClassifyDTO;
import com.bw.produce.domain.vo.ClassifySelectVO;
import com.bw.produce.domain.vo.ClassifyVO;
import com.bw.produce.query.ClassifyQueryObject;
import com.bw.produce.service.IClassifyService;
import com.bw.system.api.domain.SysFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author lemon
 * @date 2024/11/14 22:26
 **/
@RestController
@RequestMapping("/classify")
public class ClassifyController extends BaseController {
    @Autowired
    private IClassifyService classifyService;

    /**
     * 获取分类列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ClassifyQueryObject queryParams){
        startPage();
        List<ClassifyVO> list = classifyService.selectClassifyList(queryParams);
        return getDataTable(list);
    }


    /**
     * 获取分类下拉框
     */
    @GetMapping("/getFirstClassify")
    public AjaxResult list( ){
        List<ClassifySelectVO> list = classifyService.getFirstClassify();
        return AjaxResult.success(list);
    }


    /**
     * 新增分类
     */
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ClassifyDTO classifyDTO) {
        classifyService.insertClassify(classifyDTO);
        return toAjax(true);
    }


    /**
     * 修改分类
     */
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ClassifyDTO classifyDTO) {
        classifyService.updateClassify(classifyDTO);
        return toAjax(true);
    }

    /**
     * 删除分类
     */
    @DeleteMapping("/{classifyId}")
    public AjaxResult remove(@PathVariable Long[] classifyId) {
        classifyService.deleteClassifyById(classifyId);
        return toAjax(true);
    }


    /**
     * 根据参数编号获取详细信息
     */
    @GetMapping("/{classifyId}")
    public AjaxResult getInfo(@PathVariable Long classifyId) {
        return success(classifyService.getInfo(classifyId));
    }

    /**
     * 修改是否导航卡栏
     */
    @PutMapping("/changeNavigation/{classifyId}")
    public AjaxResult changeNavigation(@PathVariable Long classifyId) {
        classifyService.changeNavigation(classifyId);
        return toAjax(true);
    }

    /**
     * 修改是否显示
     */
    @PutMapping("/changeReveal/{classifyId}")
    public AjaxResult changeReveal(@PathVariable Long classifyId) {
        classifyService.changeReveal(classifyId);
        return toAjax(true);
    }



}
